import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../controllers/company_list_controller.dart';
import 'package:banquanjie_app/app/widget/common/customScaffold.dart';
import 'package:banquanjie_app/app/services/screenAdapter.dart';
import 'package:banquanjie_app/app/widget/common/dropdownMenu.dart';
import 'package:banquanjie_app/app/widget/company/cardList.dart';
// CompanyListCard
class CompanyListView extends GetView<CompanyListController> {
  const CompanyListView({super.key});
  Widget _buildDropdownMenu() {
    return DropDownMenu(
      closeCallBack: () {
        controller.closeSearchMask();
      },
      controller: controller.dropDownMenuController,
      items: const ['品牌公司类别', '首字母'],
      dropItems: [
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Obx(() => Padding(
              padding: EdgeInsets.all(ScreenAdapter.width(20)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Wrap(
                    runSpacing: ScreenAdapter.width(30),
                    spacing: ScreenAdapter.width(8),
                    children: [
                      for(int i = 0; i < controller.dicList['brandTypeList'].length; i++)
                        InkWell(
                          onTap: (){
                            controller.setSearchQueryValue('brandType', controller.dicList['brandTypeList'][i]['id']);
                          },
                          child: Container(
                            padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(8)),
                            constraints: BoxConstraints(
                              minWidth: ScreenAdapter.width(170)
                            ),
                            height: ScreenAdapter.width(56),
                            decoration: BoxDecoration(
                              color: controller.tempQuery['brandType'] == controller.dicList['brandTypeList'][i]['id'] ? Color.fromRGBO(0,178,119,.1) : Color(0xFFF7F7F7),
                              borderRadius: BorderRadius.circular(ScreenAdapter.width(56))
                            ),
                            child: Text(
                              controller.dicList['brandTypeList'][i]['dicName'], 
                              textAlign: TextAlign.center, 
                              style: TextStyle(
                                height: 2.15, 
                                fontSize: ScreenAdapter.fontSize(26), 
                                color: controller.tempQuery['brandType'] == controller.dicList['brandTypeList'][i]['id'] ? Color(0xFF00b277) : Colors.black)
                              )
                          )
                        ),
                    ]
                  ),
                ],
              )
            )),
            Container(
              margin: EdgeInsets.only(top: ScreenAdapter.width(10)),
              padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(38)),
              height: ScreenAdapter.width(146),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                border: Border(top: BorderSide(color: Color(0xfff3f8ff)))
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Expanded(
                    flex: 1,
                    child: SizedBox(
                      height: ScreenAdapter.width(80),
                      child: ElevatedButton(
                        onPressed: (){
                          controller.onClearCondition('brandType');
                        }, 
                        style: ButtonStyle(
                          padding: WidgetStatePropertyAll(EdgeInsets.all(0)),
                          shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(ScreenAdapter.width(12)))),
                          backgroundColor: WidgetStateProperty.all(Color(0xffF4F4F4)),
                        ),
                        child: Text('清空条件', style: TextStyle(color: Colors.black, fontSize: ScreenAdapter.fontSize(28)))
                      )
                    ),
                  ),
                  SizedBox(width: ScreenAdapter.width(20)),
                  Expanded(
                    flex: 1,
                    child: SizedBox(
                    height: ScreenAdapter.width(80),
                    child: ElevatedButton(
                      onPressed: (){
                        controller.onSearch();
                      }, 
                      style: ButtonStyle(
                        padding: WidgetStatePropertyAll(EdgeInsets.all(0)),
                        shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(ScreenAdapter.width(12)))),
                        backgroundColor: WidgetStateProperty.all(Color(0xff00b277)),
                      ),
                      child: Text('确定', style: TextStyle(color: Colors.white, fontSize: ScreenAdapter.fontSize(28)))
                    )
                  )
                )
                ],
              )
            )
          ]
        ),
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Obx(() => Padding(
              padding: EdgeInsets.all(ScreenAdapter.width(20)),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Wrap(
                    runSpacing: ScreenAdapter.width(30),
                    spacing: ScreenAdapter.width(8),
                    children: [
                      for(int i = 0; i < controller.dicList['initialList'].length; i++)
                        InkWell(
                          onTap: (){
                            controller.setSearchQueryValue('initial', controller.dicList['initialList'][i]);
                          },
                          child: Container(
                            padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(8)),
                            constraints: BoxConstraints(
                              minWidth: ScreenAdapter.width(170)
                            ),
                            height: ScreenAdapter.width(56),
                            decoration: BoxDecoration(
                              color: controller.tempQuery['initial'] == controller.dicList['initialList'][i] ? Color.fromRGBO(0,178,119,.1) : Color(0xFFF7F7F7),
                              borderRadius: BorderRadius.circular(ScreenAdapter.width(56))
                            ),
                            child: Text(
                              controller.dicList['initialList'][i], 
                              textAlign: TextAlign.center, 
                              style: TextStyle(
                                height: 2.15, 
                                fontSize: ScreenAdapter.fontSize(26), 
                                color: controller.tempQuery['initial'] == controller.dicList['initialList'][i] ? Color(0xFF00b277) : Colors.black)
                              )
                          )
                        ),
                    ]
                  ),
                ],
              )
            )),
            Container(
              margin: EdgeInsets.only(top: ScreenAdapter.width(10)),
              padding: EdgeInsets.symmetric(horizontal: ScreenAdapter.width(38)),
              height: ScreenAdapter.width(146),
              alignment: Alignment.center,
              decoration: BoxDecoration(
                border: Border(top: BorderSide(color: Color(0xfff3f8ff)))
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Expanded(
                    flex: 1,
                    child: SizedBox(
                      height: ScreenAdapter.width(80),
                      child: ElevatedButton(
                        onPressed: (){
                          controller.onClearCondition('initial');
                        }, 
                        style: ButtonStyle(
                          padding: WidgetStatePropertyAll(EdgeInsets.all(0)),
                          shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(ScreenAdapter.width(12)))),
                          backgroundColor: WidgetStateProperty.all(Color(0xffF4F4F4)),
                        ),
                        child: Text('清空条件', style: TextStyle(color: Colors.black, fontSize: ScreenAdapter.fontSize(28)))
                      )
                    ),
                  ),
                  SizedBox(width: ScreenAdapter.width(20)),
                  Expanded(
                    flex: 1,
                    child: SizedBox(
                    height: ScreenAdapter.width(80),
                    child: ElevatedButton(
                      onPressed: (){
                        controller.onSearch();
                      }, 
                      style: ButtonStyle(
                        padding: WidgetStatePropertyAll(EdgeInsets.all(0)),
                        shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(ScreenAdapter.width(12)))),
                        backgroundColor: WidgetStateProperty.all(Color(0xff00b277)),
                      ),
                      child: Text('确定', style: TextStyle(color: Colors.white, fontSize: ScreenAdapter.fontSize(28)))
                    )
                  )
                )
                ],
              )
            )
          ]
        ),
      ],
      selectedColor: Colors.black,
    );
  }
  @override
  Widget build(BuildContext context) {
    return Customscaffold(
      title: '品牌公司', 
      child: Obx(() => Column(
        children: [
          Container(
            width: double.infinity,
            height: ScreenAdapter.width(88),
            decoration: BoxDecoration(
              color: Colors.white,
              border: Border(top: BorderSide(color: Color(0XFFF4F7FC)))
            ),
            child: _buildDropdownMenu()
          ),
          Expanded( 
            flex: 1,
            child: RefreshIndicator(
              onRefresh: () {
                return controller.onRefresh();
              },
              child: controller.total.value == 0 ? Center(child: Text('暂无数据')) : ListView.builder(
                controller: controller.scrollController,
                padding: EdgeInsets.all(ScreenAdapter.height(20)),
                itemCount: controller.companyList.length,
                itemBuilder: (context, index) {
                  return Column(
                    children: [
                      Padding(
                        padding: EdgeInsets.only(bottom: ScreenAdapter.height(20)), 
                        child: CompanyListCard(
                          item: controller.companyList[index],
                        )
                      ),
                      if (controller.total.value == controller.companyList.length && index == controller.companyList.length - 1) 
                        Text('到底了', style: TextStyle(height: 2,color: Colors.black,fontSize: ScreenAdapter.fontSize(28)),)
                    ],
                  );
                }
              )
            )
          )
        ])
      )
    );
  }
}
